package com.hyt.it.ogt.kq.service.govData.service.bm.impl;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.function.Function;
import java.util.stream.Collectors;

import javax.annotation.Resource;

import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.math.NumberUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.hyt.common.apiInfor.ApiResponse;
import com.hyt.core.base.BaseServiceImpl;
import com.hyt.core.enums.DelFlagEnum;
import com.hyt.core.util.RemoteUtil;
import com.hyt.core.util.UUIDUtils;
import com.hyt.it.ogt.cj.enums.ComponentTypeEnum;
import com.hyt.it.ogt.cj.model.entity.ProjectCollectInfo;
import com.hyt.it.ogt.cj.model.entity.ProjectCollectInfoOption;
import com.hyt.it.ogt.cj.model.entity.ProjectImageStandard;
import com.hyt.it.ogt.cj.service.IProjectCollectInfoOptionService;
import com.hyt.it.ogt.cj.service.IProjectCollectInfoService;
import com.hyt.it.ogt.cj.service.IProjectImageStandardService;
import com.hyt.it.ogt.kq.common.bm.enums.BmPayStatusEnum;
import com.hyt.it.ogt.kq.common.bm.enums.BmProjectNeedPayEnum;
import com.hyt.it.ogt.kq.common.bm.utils.ImageUtil;
import com.hyt.it.ogt.kq.common.config.ConfigManager;
import com.hyt.it.ogt.kq.common.utils.KqStringUtils;
import com.hyt.it.ogt.kq.service.bm.feign.sq.SqClient;
import com.hyt.it.ogt.kq.service.bm.mapper.ProjectExamMapper;
import com.hyt.it.ogt.kq.service.bm.mapper.ProjectMapper;
import com.hyt.it.ogt.kq.service.bm.model.dto.ProjectStatusAttrDto;
import com.hyt.it.ogt.kq.service.bm.model.entity.Project;
import com.hyt.it.ogt.kq.service.bm.model.entity.ProjectExam;
import com.hyt.it.ogt.kq.service.bm.model.entity.ProjectSubject;
import com.hyt.it.ogt.kq.service.bm.model.entity.StudentInfo;
import com.hyt.it.ogt.kq.service.bm.model.entity.StudentSubject;
import com.hyt.it.ogt.kq.service.bm.service.IProjectService;
import com.hyt.it.ogt.kq.service.bm.service.IProjectSubjectService;
import com.hyt.it.ogt.kq.service.bm.service.IStudentInfoService;
import com.hyt.it.ogt.kq.service.bm.service.IStudentSubjectService;
import com.hyt.it.ogt.kq.service.bm.service.impl.BmBaseService;
import com.hyt.it.ogt.kq.service.gov.feign.pt.GovPtClient;
import com.hyt.it.ogt.kq.service.gov.model.dto.AreaDTO;
import com.hyt.it.ogt.kq.service.gov.model.dto.ExamSubjectDTO;
import com.hyt.it.ogt.kq.service.govData.service.bm.IProjectStudentService;
import com.hyt.it.ogt.kq.service.model.entity.Candidate;
import com.hyt.it.ogt.kq.service.model.entity.CandidatePhoto;
import com.hyt.it.ogt.kq.service.model.entity.CandidateSubject;
import com.hyt.it.ogt.kq.service.model.entity.Subject;
import com.hyt.it.ogt.kq.service.model.entity.TaskCandidateArea;
import com.hyt.it.ogt.kq.service.model.entity.admission.CandidateInfo;
import com.hyt.it.ogt.kq.service.model.vo.candidateSubject.BmTaskData;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.map.MapUtil;
import cn.hutool.core.text.StrPool;
import cn.hutool.core.util.StrUtil;
import lombok.extern.slf4j.Slf4j;

@Slf4j
@Service
public class ProjectStudentServiceImpl extends BaseServiceImpl<ProjectMapper, Project> implements IProjectStudentService {

    @Autowired
    private ProjectExamMapper projectExamMapper;
    @Autowired
    private IStudentSubjectService iStudentSubjectService;
    @Autowired
    private IProjectSubjectService iProjectSubjectService;
    @Autowired
    private IProjectCollectInfoService iProjectCollectInfoService;
    @Autowired
    private ConfigManager configManager;
    @Autowired
    private IProjectCollectInfoOptionService iProjectCollectInfoOptionService;
    @Resource
    IProjectImageStandardService iProjectImageStandardService;
    @Autowired
    private IProjectService iProjectService;
    @Resource
    IStudentInfoService iStudentInfoService;
    @Resource
    private SqClient sqClient;
    @Resource
    private RedisTemplate<String, Object> redisTemplate;
    @Resource
    private GovPtClient govPtClient;

    @Override
    public BmTaskData getBmTaskDataByProjectIdAndTaskId(String userId, String taskId, String projectId, String processKey) {
        log.info("## 考试同步查询报名数据 taskId:{},projectId:{}", taskId, projectId);
        BmTaskData bmTaskData = new BmTaskData();
        try {
            Project project = iProjectService.getById(projectId);
            if (null == project) {
                return bmTaskData;
            }
            // 初始化考务绑定报名信息
            initrojectExamInfo(userId, taskId, projectId);

            // 获取区域采集信息定义
            ProjectCollectInfo areaProjectCollectInfo = getAreaProjectCollectInfo(projectId);
            List<ProjectCollectInfoOption> projectCollectInfoOptions = getAreaProjectCollectInfoOptions(areaProjectCollectInfo);
            // 获取平台区域map
            Map<String, AreaDTO>  ptAreaMaps = getPtOfficeArea(projectCollectInfoOptions);
            // 设置区域信息
            List<TaskCandidateArea> areaList = getTaskCandidateAreas(taskId, projectCollectInfoOptions, ptAreaMaps);
           
            
            bmTaskData.setTaskCandidateAreaList(areaList);

            // 查询项目下所有的科目
            List<ProjectSubject> projectSubjects = iProjectSubjectService.querySubjectList(project.getId(), null);
            ProjectStatusAttrDto selectAllStudentStatusDto = BmBaseService.getSelectProjectStatusAttrDto(projectSubjects, project);
            String columns = iProjectSubjectService.getSqlColumn(projectId);
            log.info("## queryAllStudent columns:[{}], projectId:{}, isPay:{}, isAudit:{}", columns, projectId, selectAllStudentStatusDto.getIsPay(), selectAllStudentStatusDto.getIsAudit());

            List<Map<String, Object>> studentList = new ArrayList<>();
            int pageNo = 1;
            int pageSize = configManager.getBmMaxPageSize();
            while (true) {
                //List<Map<String, Object>> studentListTemp = iProjectSubjectService.queryAllStudent(columns, projectId, null, selectAllStudentStatusDto.getIsPay(), selectAllStudentStatusDto.getIsAudit(), pageNo, pageSize);
                List<Map<String, Object>> studentListTemp = iProjectSubjectService.queryAllStudent(columns, projectId, null, null, selectAllStudentStatusDto.getIsAudit(), pageNo, pageSize);
                if (CollectionUtils.isNotEmpty(studentListTemp)) {
                    pageNo++;
                    log.info("## pageNo{},pageSize:{}", pageNo, pageSize);
                    studentList.addAll(studentListTemp);
                } else {
                    break;
                }
            }

            redisTemplate.opsForValue().set(processKey, 15);

            List<Candidate> candidateList = new ArrayList<Candidate>();
            List<CandidatePhoto> candidatePhotoList = new ArrayList<CandidatePhoto>();
            Map<String, String> studentMap = new HashMap<String, String>();
            if (CollectionUtils.isNotEmpty(studentList)) {
                for (int i = 0; i < studentList.size(); i++) {
                    Map<String, Object> map = studentList.get(i);
                    Candidate candidate = new Candidate();
                    String office = MapUtil.getStr(map, "office");
                    if (StrUtil.isNotBlank(office)) {
                        // 获取逗号拼接的最后一个层级
                        List<String> officeSplit = StrUtil.split(office, StrPool.COMMA);
                        office = CollUtil.getLast(officeSplit);
                        candidate.setDeptId(office);
                    }
                    String name = String.valueOf(map.get("name"));
                    if (KqStringUtils.isNotNullOrNotEmpty(name)) {
                        candidate.setName(name);
                    }
                    String birthday = String.valueOf(map.get("birthday"));
                    if (KqStringUtils.isNotNullOrNotEmpty(birthday)) {
                        candidate.setBirthday(birthday);
                    }
                    String sex = String.valueOf(map.get("sex"));
                    if (KqStringUtils.isNotNullOrNotEmpty(sex) && "0".equals(sex)) {
                        candidate.setSex(1);
                    }
                    if (KqStringUtils.isNotNullOrNotEmpty(sex) && "1".equals(sex)) {
                        candidate.setSex(2);
                    }
                    String idType = String.valueOf(map.get("certificatetype"));
                    if (KqStringUtils.isNotNullOrNotEmpty(idType) && NumberUtils.isCreatable(idType)) {
                        candidate.setIdType(Integer.valueOf(idType));
                    }
                    String phone = String.valueOf(map.get("phone"));
                    if (KqStringUtils.isNotNullOrNotEmpty(phone)) {
                        candidate.setPhone(phone);
                    }
                    String email = String.valueOf(map.get("email"));
                    if (KqStringUtils.isNotNullOrNotEmpty(email)) {
                        candidate.setEmail(email);
                    }
                    String studentId = String.valueOf(map.get("student_id"));
                    if (KqStringUtils.isNotNullOrNotEmpty(studentId)) {
                        candidate.setBmStudentId(studentId);
                    }
                    String idNumber = String.valueOf(map.get("idcard"));
                    if (KqStringUtils.isNotNullOrNotEmpty(idNumber)) {
                        candidate.setIdNumber(idNumber);
                        studentMap.put(studentId, studentId);
                    }
                    String admissionno = String.valueOf(map.get("admissionno"));
                    if (KqStringUtils.isNotNullOrNotEmpty(admissionno)) {
                        candidate.setAdmissionno(admissionno.toUpperCase());
                    }
                    String area = String.valueOf(map.get("area"));
                    if (KqStringUtils.isNotNullOrNotEmpty(area)) {
                        // 获取逗号拼接的最后一个层级
                        List<String> areaSplit = StrUtil.split(area, StrPool.COMMA);
                        area = CollUtil.getLast(areaSplit);
                        // 判断节点是不是平台区域编码
                        AreaDTO areaDTO =  ptAreaMaps.get(area);
                        if(null != areaDTO) {
                            if(areaDTO.getRegionLevel().equals(3)) {
                                candidate.setDistrict(area);
                                if (CollUtil.isNotEmpty(areaList)) {
                                    // 获取城市code
                                    for (TaskCandidateArea taskCandidateArea : areaList) {
                                        if (StrUtil.equals(taskCandidateArea.getAreaId(), area)) {
                                            candidate.setCity(taskCandidateArea.getParentId());
                                        }
                                    }
                                }
                                if (CollUtil.isNotEmpty(areaList)) {
                                    // 获取省份code
                                    for (TaskCandidateArea taskCandidateArea : areaList) {
                                        if (StrUtil.equals(taskCandidateArea.getAreaId(), candidate.getCity())) {
                                            candidate.setProvince(taskCandidateArea.getParentId());
                                        }
                                    }
                                }
                            }
                            if(areaDTO.getRegionLevel().equals(2)) {
                                candidate.setCity(area);
                                if (CollUtil.isNotEmpty(areaList)) {
                                    // 获取省份code
                                    for (TaskCandidateArea taskCandidateArea : areaList) {
                                        if (StrUtil.equals(taskCandidateArea.getAreaId(), candidate.getCity())) {
                                            candidate.setProvince(taskCandidateArea.getParentId());
                                        }
                                    }
                                }
                            }
                            if(areaDTO.getRegionLevel().equals(1)) {
                                candidate.setProvince(area);
                            }
                        }else {
                            candidate.setDistrict(area);
                            if (CollUtil.isNotEmpty(areaList)) {
                                // 获取城市code
                                for (TaskCandidateArea taskCandidateArea : areaList) {
                                    if (StrUtil.equals(taskCandidateArea.getAreaId(), area)) {
                                        candidate.setCity(taskCandidateArea.getParentId());
                                    }
                                }
                            }
                            if (CollUtil.isNotEmpty(areaList)) {
                                // 获取省份code
                                for (TaskCandidateArea taskCandidateArea : areaList) {
                                    if (StrUtil.equals(taskCandidateArea.getAreaId(), candidate.getCity())) {
                                        candidate.setProvince(taskCandidateArea.getParentId());
                                    }
                                }
                            }
                        }
                    }
                    String idPhoto = String.valueOf(map.get("certificatephoto"));
                    if (KqStringUtils.isNotNullOrNotEmpty(idPhoto)) {
                        List<String> idPhotos = StrUtil.split(idPhoto, StrPool.COMMA);
                        if (CollUtil.isNotEmpty(idPhotos)) {
                            for (String photoPath : idPhotos) {
                                if (KqStringUtils.isNotBlank(photoPath)) {
                                    CandidatePhoto candidatePhoto = new CandidatePhoto();
                                    candidatePhoto.setCandidateId(MapUtil.getStr(map, "student_id"));
                                    Optional.ofNullable(photoPath).filter(StrUtil::isNotBlank).ifPresent(data -> {
                                        // 图片名称
                                        String imageName = ImageUtil.getImageName(photoPath);
                                        candidatePhoto.setName(imageName);

                                        // 完整的图片路径
                                        if (KqStringUtils.isNotNullOrNotEmpty(photoPath) && (photoPath.startsWith("http://") || photoPath.startsWith("https://"))) {
                                            candidatePhoto.setPhotoPath(photoPath);
                                        }
                                        if (KqStringUtils.isNotNullOrNotEmpty(photoPath) && !(photoPath.startsWith("http://") || photoPath.startsWith("https://"))) {
                                            // 完整的图片路径
                                            String imageFullPath = ImageUtil.getImageFullPath(photoPath, configManager.getFilePath());
                                            candidatePhoto.setPhotoPath(imageFullPath);
                                        }
                                    });
                                    candidatePhotoList.add(candidatePhoto);
                                }
                            }
                        }
                    }
                    candidateList.add(candidate);
                }
            }
            bmTaskData.setCandidateList(candidateList);
            bmTaskData.setCandidatePhotoList(candidatePhotoList);

            // 获取报名的所有组件
            List<ProjectCollectInfo> projectCollectInfos = iProjectCollectInfoService.getProjectCollectInfosByPid(projectId);
            // 获取所有cascader组件project_collect_info_id
            List<String> cascaderIds = projectCollectInfos.stream()
                    .filter(data -> StrUtil.equals(data.getComponentType(), ComponentTypeEnum.cascader.getType()))
                    .map(ProjectCollectInfo::getId)
                    .distinct()
                    .collect(Collectors.toList());

            // 获取所有的考生信息
            List<CandidateInfo> candidateInfoList = new ArrayList<>();
            int infoPageNo = 1;
            while (true) {
                List<StudentInfo> studentInfoListTemp = iStudentInfoService.queryAllStudentInfo(projectId, selectAllStudentStatusDto.getIsPay(), selectAllStudentStatusDto.getIsAudit(), infoPageNo, pageSize);
                if (CollectionUtils.isEmpty(studentInfoListTemp)) {
                    break;
                }

                // 如果组件属于下拉复选框，那么取最后一个参数
                for (StudentInfo studentInfo : studentInfoListTemp) {
                    if (CollUtil.contains(cascaderIds, studentInfo.getProjectCollectInfoId())) {
                        Optional.ofNullable(studentInfo.getValue())
                                .filter(StrUtil::isNotBlank)
                                .map(data -> StrUtil.split(data, StrPool.COMMA))
                                .map(CollUtil::getLast)
                                .filter(StrUtil::isNotBlank)
                                .ifPresent(studentInfo::setValue);
                    }
                }

                log.info("## 获取考生CandidateInfo infoPageNo:{},pageSize:{}，dataSize:{}", infoPageNo, pageSize, studentInfoListTemp.size());
                List<CandidateInfo> candidateInfos = studentInfoListTemp.stream()
                        .map(data -> BeanUtil.toBean(data, CandidateInfo.class))
                        .collect(Collectors.toList());
                candidateInfoList.addAll(candidateInfos);
                infoPageNo++;
            }
            bmTaskData.setCandidateInfoList(candidateInfoList);

            redisTemplate.opsForValue().set(processKey, 25);

            // 获取科目信息
            List<ProjectSubject> projectSubjectList = iProjectSubjectService.querySubjectList(projectId, null);
            List<Subject> subjectList = new ArrayList<Subject>();
            if (projectSubjectList != null && projectSubjectList.size() > 0) {
                for (int i = 0; i < projectSubjectList.size(); i++) {
                    ProjectSubject projectSubject = projectSubjectList.get(i);
                    // 获取远程的科目信息
                    ExamSubjectDTO examSubjectDTO = RemoteUtil.getOrThrows(() -> sqClient.querySubjectById(projectSubject.getSubjectId()));
                    // 同步科目信息
                    Subject subject = new Subject();
                    BeanUtil.copyProperties(examSubjectDTO, subject);
                    subject.setId(UUIDUtils.newSortUUID());
                    subject.setName(projectSubject.getSubjectName());
                    subject.setTaskId(taskId);
                    subject.setOfficeId(projectSubject.getOfficeId());
                    subject.setDeptId(projectSubject.getDeptId());
                    subject.setBmSubjectId(projectSubject.getId());
                    subjectList.add(subject);
                }
            }
            bmTaskData.setSubjectList(subjectList);
            log.info("## queryStudentSubject projectId:{}, isPay:{}, isAudit:{}", projectId, selectAllStudentStatusDto.getIsPay(), selectAllStudentStatusDto.getIsAudit());
            //List<StudentSubject> studentSubjectList = iStudentSubjectService.queryStudentSubject(selectAllStudentStatusDto.getIsAudit(), selectAllStudentStatusDto.getIsPay(), null, null, null, projectId);
            List<StudentSubject> studentSubjectList = iStudentSubjectService.queryStudentSubject(selectAllStudentStatusDto.getIsAudit(), null, null, null, null, projectId);

            List<CandidateSubject> candidateSubjectList = new ArrayList<CandidateSubject>();
            if (CollectionUtils.isNotEmpty(studentSubjectList)) {
                Map<String, String> subjectIdsMap = new HashMap<>();
                Map<String, ProjectSubject> projectSubjectsMap = new HashMap<>();
                List<ProjectSubject> projectSubjectsTemp = iProjectSubjectService.querySubjectList(projectId, null);
                if (CollectionUtils.isNotEmpty(projectSubjectsTemp)) {
                    for (ProjectSubject projectSubject : projectSubjectsTemp) {
                        subjectIdsMap.put(projectSubject.getSubjectId(), projectSubject.getId());
                        projectSubjectsMap.put(projectSubject.getSubjectId(), projectSubject);
                    }
                }
                for (StudentSubject studentSubject : studentSubjectList) {
                    CandidateSubject candidateSubject = new CandidateSubject();
                    candidateSubject.setCandidateId(studentSubject.getStudentId());
                    if (studentMap != null) {
                        candidateSubject.setCandidateId(studentMap.get(studentSubject.getStudentId()));
                    }
                    candidateSubject.setSubjectId(subjectIdsMap.get(studentSubject.getSubjectId()));
                    candidateSubject.setTaskId(taskId);
                    // 看科目需不需要缴费
                    ProjectSubject projectSubject = projectSubjectsMap.get(studentSubject.getSubjectId());
                    // 如果科目需要缴费
                    if (null != projectSubject && BmProjectNeedPayEnum.PAY.getPayStatus().equals(projectSubject.getIsPay())) {
                        // 考生报考科目是否已经缴费
                        if (null != studentSubject.getPay() && BmPayStatusEnum.PAY.getPayStatus().equals(studentSubject.getPay())) {
                            candidateSubjectList.add(candidateSubject);
                        }
                    }
                    if (null != projectSubject && BmProjectNeedPayEnum.UNPAY.getPayStatus().equals(projectSubject.getIsPay())) {
                        // 考生报考科目是否已经缴费
                        candidateSubjectList.add(candidateSubject);
                    }
                }
            }
            bmTaskData.setCandidateSubjectList(candidateSubjectList);
            bmTaskData.setOfficeId(project.getOfficeId());

            // 获取报名采集信息
            bmTaskData.setProjectCollectInfos(projectCollectInfos);
            log.debug("# 获取报名项目采集信息：{}", CollUtil.size(projectCollectInfos));
            bmTaskData.setProjectCollectInfoOptions(projectCollectInfoOptions);
            log.debug("# 获取报名项目采集信息选项：{}", CollUtil.size(projectCollectInfoOptions));
            List<ProjectImageStandard> projectImageStandards = iProjectImageStandardService.queryByProjectId(projectId);
            bmTaskData.setProjectImageStandards(projectImageStandards);
            log.debug("# 获取报名图片规格表：{}", CollUtil.size(projectImageStandards));

            log.info("## 考试同步查询报名数据结束 {}，{}", taskId, projectId);
        } catch (Exception ex) {
            throw ex;
        }
        return bmTaskData;
    }

    private List<TaskCandidateArea> getTaskCandidateAreas(String taskId, List<ProjectCollectInfoOption> optionList, Map<String, AreaDTO>  ptAreaMaps) {
        List<TaskCandidateArea> areaList = new ArrayList<TaskCandidateArea>();
        if (CollectionUtils.isNotEmpty(optionList)) {
            for (ProjectCollectInfoOption projectCollectInfoOption : optionList) {
                TaskCandidateArea area = new TaskCandidateArea();
                AreaDTO areaDTO = ptAreaMaps.get(projectCollectInfoOption.getOptionValue());
                if(null != areaDTO) {
                    Integer ptLevel = areaDTO.getRegionLevel();
                    if(null != ptLevel) {
                        area.setType(String.valueOf(Integer.sum(ptLevel, 1))); 
                    }
                }
                area.setAreaId(projectCollectInfoOption.getOptionValue());
                area.setParentId(projectCollectInfoOption.getParentOptionValue());
                area.setTaskId(taskId);
                area.setName(projectCollectInfoOption.getOptionLabel());
                areaList.add(area);
            }
        }
        return areaList;
    }
    
    
    
    private Map<String, AreaDTO>  getPtOfficeArea(List<ProjectCollectInfoOption> projectCollectInfoOptions) {
        // 证件类型
        Map<String, AreaDTO> areaMaps = new HashMap<>();
        List<String> areaIds = new ArrayList<>();
        if(CollUtil.isNotEmpty(projectCollectInfoOptions)) {
            areaIds = projectCollectInfoOptions.stream().map(ProjectCollectInfoOption::getOptionValue).collect(Collectors.toList());
        }
        if(CollUtil.isNotEmpty(areaIds)) {
            ApiResponse<Object> areaRes = govPtClient.getAreaByIds(areaIds);
            if(Objects.equals(20000,areaRes.getCode()) && null != areaRes.getData()){
                List<AreaDTO> dtos = JSON.parseArray(JSON.toJSONString(areaRes.getData()),AreaDTO.class);
                if (CollUtil.isNotEmpty(dtos)) {
                    areaMaps = dtos.stream().collect(Collectors.toMap(AreaDTO::getId, Function.identity()));
                }
            }
        }
        return areaMaps;
    }

    private ProjectCollectInfo getAreaProjectCollectInfo(String projectId) {
        ProjectCollectInfo projectCollectInfo = null;
        QueryWrapper<ProjectCollectInfo> wrapper = new QueryWrapper<ProjectCollectInfo>();
        wrapper.eq("project_id", projectId);
        wrapper.eq("is_del_flag", "0");
        wrapper.orderByAsc("order_num");
        List<ProjectCollectInfo> list = iProjectCollectInfoService.list(wrapper);
        for (int i = 0; i < list.size(); i++) {
            if ("area".equals(list.get(i).getComponentName())) {
                projectCollectInfo = list.get(i);
            }
        }
        return projectCollectInfo;
    }
    
    private List<ProjectCollectInfoOption> getAreaProjectCollectInfoOptions(ProjectCollectInfo areaProjectCollectInfo) {
        List<ProjectCollectInfoOption> optionList = new ArrayList<ProjectCollectInfoOption>();
        if (areaProjectCollectInfo != null) {
            QueryWrapper<ProjectCollectInfoOption> optionWrapper = new QueryWrapper<ProjectCollectInfoOption>();
            optionWrapper.lambda()
                .eq(ProjectCollectInfoOption::getProjectId, areaProjectCollectInfo.getProjectId())
                .eq(ProjectCollectInfoOption::getProjectCollectInfoId, areaProjectCollectInfo.getId())
                .eq(ProjectCollectInfoOption::getDelFlag, DelFlagEnum.NORMAL.getCode())
                .orderByAsc(ProjectCollectInfoOption::getOrderNum);
            optionList = iProjectCollectInfoOptionService.list(optionWrapper);
        }
        return optionList;
    }

    private ProjectExam initrojectExamInfo(String userId, String taskId, String projectId) {
        ProjectExam projectExam = projectExamMapper.getProjectExamByBmProjectId(projectId);
        if (null != projectExam) {
            projectExam.setProjectId(projectId);
            projectExam.setExamId(taskId);
            projectExamMapper.updateById(projectExam);
        } else {
            projectExam = new ProjectExam();
            projectExam.setId(UUIDUtils.newSortUUID());
            projectExam.setExamId(taskId);
            projectExam.setProjectId(projectId);
            LocalDateTime nowTime = LocalDateTime.now();
            projectExam.setCreateDate(nowTime);
            projectExam.setUpdateDate(nowTime);
            projectExam.setDelFlag(false);
            projectExam.setCreateBy(userId);
            projectExam.setUpdateBy(userId);
            projectExamMapper.insert(projectExam);
        }
        return projectExam;
    }
}
